<?php
class AdminUsersNewController extends AdminIndexController
{
    public function getTemplateName()
    {
        return 'AdminUserEdit.tpl';
    }
    
    public function prepare()
    {
        ApplicationController::attachEventListener($this, array($_POST, 'UserSaveAction'));
    }
    
    public function exec()
    {
        $response = array(
            'error' => 1,
            'text'  => 'При попытке сохранения произошла ошибка'
        );
        
        $email    = Env::post('email');
        $password = Env::post('password');
        $status   = Env::post('status');

        $users_model = new UsersModel(DbConnection::COMMON_SPACE, true);
        
        if ($users_model->insert($email, $password, $status)) {
            $response['error'] = 0;
            $response['text']  = '';
        }
        
        echo json_encode($response);
        die();
    }
}